<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_couponfree\Entity\ShusyCouponfree;

class CouponfreeItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_couponfree';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyCouponfree) {
      $coupon = CouponItem::init($this->entity->coupon_id);
      $value = $coupon;
      $this->merge($value);

      $value = [
        'op' => $this->getOp($this->entity),
      ];
      $this->merge($value);
    }
  }

  protected function getOp(ShusyCouponfree $couponfree) {
    $t = shusy_couponfree_log_load_multiple(FALSE, ['couponfree_id' => $couponfree->id]);
    if (empty($t)) {
      return '立即领取';
    }
    return '已领取';
  }
}
